package com.example.springlearn.util;

import com.example.springlearn.bean.AnsInfo;
import com.example.springlearn.bean.QuestionInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AnswerUtil {

    public static Map<QuestionInfo, Boolean> answerState(List<QuestionInfo> questionInfos, List<AnsInfo> ansInfos) {

        Map<QuestionInfo, Boolean> ansStates = new HashMap<>(questionInfos.size());
        for (QuestionInfo questionInfo : questionInfos) {
            AnsInfo ansInfo = getAnsInfoByQid(ansInfos, questionInfo.getQid());
            if (ansInfo == null) {
                ansStates.put(questionInfo, null);
            } else {
                ansStates.put(questionInfo, ansInfo.getIsTrue());
            }
        }

        return ansStates;
    }

    private static AnsInfo getAnsInfoByQid(List<AnsInfo> ansInfos, Integer qid) {
        for (AnsInfo ansInfo : ansInfos) {
            if (ansInfo.getQid().equals(qid)) {
                return ansInfo;
            }
        }

        return null;
    }

}
